package com.sgcc.pda.mdrh.task.safe.ui.ac;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;

import com.sgcc.pda.baselibrary.utils.LogUtil;
import com.sgcc.pda.lib_tools_database.bean.MeasureSummary;
import com.sgcc.pda.lib_tools_database.bean.other.ProcessRiskData;
import com.sgcc.pda.lib_tools_database.bean.other.VersionItem;
import com.sgcc.pda.lib_tools_database.factory.JSResultUtil;
import com.sgcc.pda.lib_tools_database.factory.KnowledgeCheck;
import com.sgcc.pda.lib_tools_database.factory.MeasureSummaryImpl;
import com.sgcc.pda.lib_tools_database.factory.RiskHttpStateImpl;
import com.sgcc.pda.lib_tools_database.util.DataBaseConfigTools;
import com.sgcc.pda.mdrh.task.safe.R;
import com.sgcc.pda.mdrh.task.safe.util.HttpUtil;
import com.sgcc.pda.mdrh.utils.ToolGson2;
import com.sgcc.pda.sdk.entity.BaseEntity;
import com.sgcc.pda.sdk.utils.db.SharepreferenceUtil;
import com.sgcc.pda.tools.JsonUtils;
import com.sgcc.pda.web.impl.HttpCallbackInterface;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_open_webview).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), MixWebViewActivity.class);
                intent.putExtra("webUrl", "http://www.baidu.com");
                startActivity(intent);
            }
        });
        findViewById(R.id.btn_open_asset).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), MixWebViewActivity.class);
                intent.putExtra("webUrl", "android_asset/index.html");
                startActivity(intent);
            }
        });

        // getData();
        // getCheckData();
        // LogUtil.i(new InputParam().getArrayParam());
        // LogUtil.i(JSResultUtil.getProfession());
        // LogUtil.i(JSResultUtil.getNextProfessionList("0101"));
        // LogUtil.i(JSResultUtil.getExperienceList("0202"));
        // LogUtil.i(JSResultUtil.getExperienceDetail("5"));

//        LogUtil.i(
//                JSResultUtil.getRiskCheckStateList(
//                        "092001552925",
//                        param
//                )
//        );

//        LogUtil.i(DataBaseConfigTools.isDBExist() + "");

//        final String json = "{\"appNo\":\"092001552925\",\"stepNo\":\"01010202\",\"riskPoint\":[{\"attach\":[{\"attachSrc\":\"/weblogic/app/yxgkzy/image/a5cba4e5bbcc41358fde9fc0ae8948e1.jpg\",\"attachType\":\"01\",\"localSrc\":\"\"}],\"riskNo\":\"010128\"}]}";
//
//        HttpUtil.saveRiskPointEviRecordAsync(
//                this,
//                "092001552925",
//                "01010202",
//                "[{\"attach\":[{\"attachSrc\":\"/weblogic/app/yxgkzy/image/a5cba4e5bbcc41358fde9fc0ae8948e1.jpg\",\"attachType\":\"01\",\"localSrc\":\"\"}],\"riskNo\":\"010128\"}]",
//                new HttpCallbackInterface() {
//                    @Override
//                    public void httpSuccess(String result) {
//                        LogUtil.i(result);
//                    }
//
//                    @Override
//                    public void httpFailed(int errorCode, String errorMsg) {
//                        LogUtil.i(errorCode + errorMsg);
//                        new RiskHttpStateImpl().insertData("092001552925", "01010202", json);
//                    }
//                }
//        );

        LogUtil.e(SharepreferenceUtil.getUserCode(this));

//        HttpUtil.getMeetingState(
//                this,
//                "3742020092900085",
//                "",
//                new HttpCallbackInterface() {
//
//                    @Override
//                    public void httpSuccess(String result) {
//                        LogUtil.e(result);
//                    }
//
//                    @Override
//                    public void httpFailed(int errorCode, String errorMsg) {
//                        LogUtil.e(errorCode + errorMsg);
//                    }
//                });

        //getData();
        HttpUtil.getOSSToken(
                this,
                new HttpCallbackInterface() {
                    @Override
                    public void httpSuccess(String result) {
                        LogUtil.i(result);
                    }

                    @Override
                    public void httpFailed(int errorCode, String errorMsg) {
                        LogUtil.i(errorCode + errorMsg);
                    }
                }
        );
    }

    private void getData() {
        String json = "{\"versionNo\":\"0.0.0.1\",\"tableName\":\"KN_STAN_VIDEO\",\"timestamp\":1602066115000}";
        // String json = "{\"versionNo\":\"0.0.0.1\",\"tableName\":\"KN_TYPICAL_EXP\",\"timestamp\":1602066115000}";
        // String json = "{\"versionNo\":\"0.0.0.1\",\"tableName\":\"KN_WORK_TYPE_STAN_PROC_R\",\"timestamp\":1602066115000}";

        HttpUtil.updateVersonData(
                this,
                JsonUtils.toBean(json, VersionItem.class),
                new HttpCallbackInterface() {
                    @Override
                    public void httpSuccess(String result) {
                        LogUtil.i(result);

//                        try {
//                            JSONObject obj = new JSONObject(result);
//                            if (obj.has("RT_F")
//                                    && "1".equals(obj.optString("RT_F"))) {
//                                String array = obj.optString("DTS");
//
//                                if (!TextUtils.isEmpty(array)) {
//                                    new MeasureSummaryImpl()
//                                            .insertList(JsonUtils.toList(array, MeasureSummary.class));
//                                }
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
                    }

                    @Override
                    public void httpFailed(int errorCode, String errorMsg) {
                        LogUtil.i(errorCode + errorMsg);
                    }
                });
    }

}
